#include "MainWindow.h"
#include "ui_mainwindow.h"
#include "EasyGL/EasyScene.h"

MainWindow* MainWindow::instance = NULL;
bool MainWindow::wantsChangeCamera = false;

MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) {
  ui->setupUi(this);

  instance = this;
  connect(ui->doubleSpinBox, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &MainWindow::rotateAmr);
  connect(ui->doubleSpinBox_2, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &MainWindow::rotateAmr);
  connect(ui->doubleSpinBox_3, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &MainWindow::rotateAmr);
  connect(ui->doubleSpinBox_4, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &MainWindow::rotateAmr);
  connect(ui->doubleSpinBox_5, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &MainWindow::rotateAmr);
  connect(ui->doubleSpinBox_6, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &MainWindow::rotateAmr);
}

MainWindow::~MainWindow() {
  delete ui;
}

void MainWindow::rotateAmr()
{
	ui->openGLWidget->rotate(ui->doubleSpinBox->value(), ui->doubleSpinBox_2->value(),
		ui->doubleSpinBox_3->value(), ui->doubleSpinBox_4->value(),ui->doubleSpinBox_5->value(),ui->doubleSpinBox_6->value());
}


// Listen to keypresses
void MainWindow::keyPressEvent(QKeyEvent *ev) {
    qDebug() << "Pressed: " << ev->key();
    if(ev->key() == Qt::Key_Space)
        MainWindow::wantsChangeCamera = true;
}
